package com.aaa.tmr;

import com.aaa.tmr.entity.Log;
import com.aaa.tmr.service.LogService;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Log)表控制层
 *
 * @author makejava
 * @since 2021-03-23 10:26:52
 */
@Controller
@RequestMapping("log")
public class LogController {
    /**
     * 服务对象
     */
    @Resource
    private LogService logService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Log selectOne(Integer id) {
        return this.logService.queryById(id);
    }

    /**
     * 跳转字典类型分页列表页面
     *
     * @return 列表页面
     */
    @RequestMapping("toLog")
    public String toLog() {
        return "back/log-page";
    }

    /**
     * 分页查询方法
     *
     * @param page
     * @param limit
     * @param log
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result<List> queryAll(Integer page, Integer limit, Log log) {
        PageInfo pageInfo = logService.queryAll(page, limit, log);
        return new Result<>(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param log 实例对象
     * @return 实例对象
     */
    @RequestMapping("insert")
    @ResponseBody
    public Result<Log> insert(Log log) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.logService.insert(log));
    }

    /**
     * 修改数据
     *
     * @param log 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    @ResponseBody
    public Result<Log> update(Log log) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.logService.update(log));
    }

    /**
     * 通过主键删除数据
     *
     * @param logId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    @ResponseBody
    public Result<Boolean> deleteById(Integer logId) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.logService.deleteById(logId));
    }

    /**
     * 通过主键删除数据
     *
     * @param ids 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteByIds")
    @ResponseBody
    public Result<Integer> deleteByIds(String ids) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.logService.deleteByIds(ids));
    }

    /**
     *操作图标显示页面
     *
     * @param year 年
     * @param month 月
     * @return 单条数据
     *//*
    @RequestMapping("queryshowLogData")
    @ResponseBody
    public Result<java.util.List<java.util.Map>> queryshowLogData(int year, int month) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.logService.queryShowChartData(year,month));
    }

    *//**
     * 跳转日志操作图标显示页面
     * @return
     *//*
    @GetMapping("toLogChart")
    public String toLogChart(){
        return "back/log-chart";
    }*/

}
